#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
int x[N], r[N];

void solve() {
  cin >> n >> m;
  rep(i, 1, n) cin >> x[i];
  rep(i, 1, n) cin >> r[i];
  map<int, int> mp;
  rep(i, 1, n) {
    rep(j, -r[i], r[i]) {
      int k = sqrt(1ll * r[i] * r[i] - 1ll * j * j);
      int p = x[i] + j;
      mp[p] = max(mp[p], k * 2 + 1);
    }
  }
  ll sum = 0;
  for (auto p : mp) sum += p.second;
  cout << sum << endl;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}